// mircoApp/platform_order_import/platform_order_import_recode/platform_order_import_recode.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    list: [],
    page: 1,
    total_page: 1,
    popup_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.setData({show:false});

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({show:false})
    this.record();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },
  record(page = 1) {
    app._getNetWork({
      url: app.getNetAddresss("plugin.platform-order-import.frontend.convert-record.index"),
      data: { page },
      success: resdata => {
        let { result, data, msg } = resdata.data;
        if (result !== 1) {

          return app.tips(msg);
        }
        if (page == 1) {
          this.setData({ list: data.data });
        } else {
          this.setData({ list: this.data.list.concat(data.data) });
        }
        this.data.page = data.current_page;
        this.data.total_page = data.last_page;
      }
    });

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.record(page);
  },
  goto(e) {
    let code = e.currentTarget.dataset.code;
    if (code == 'point') {
      wx.navigateTo({
        url: '/packageB/member/integral/integral',
      })
    } else if (code == 'love') {
      wx.navigateTo({
        url: '/packageB/member/love/Love_index/Love_index',
      })
    } else if (code == 'balance') {
      wx.navigateTo({
        url: '/packageA/member/balance/balance/balance',
      })
    } else if (code == 'integral') {
      wx.navigateTo({
        url: '/packageB/member/Integral_love/Integral_love',
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showPopup(e) {
    let order_id = e.currentTarget.dataset.order_id;
    app._getNetWork({
      url: app.getNetAddresss("plugin.platform-order-import.frontend.convert-record.show-reward"),
      data: { order_id },
      success: resdata => {
        let { result, data, msg } = resdata.data;
        if (result !== 1) {
          return app.tips(msg);
        }
        this.setData({ popup_list: data,show: true });
      }
    });
  },
  closeShow() {
    this.setData({
      show: false
    })
  }
})